<!-- Horizontal Form -->
 <div class="box box-info">
      <div class="box-header with-border">
        <h3 class="box-title">添加用户</h3>
      </div>
      <!-- /.box-header -->
      <!-- form start -->
      <form class="form-horizontal">
        <div class="box-body">
          <span id="msg"></span>
          <div class="form-group">
            <label for="titleId" class="col-sm-2 control-label">通知标题</label>
            <div class="col-sm-10">
              <input type="text" name="title" class="form-control" id="titleId">
            </div>
          </div>
          <div class="form-group" id="pwdDiv">
            <label for="typeId" class="col-sm-2 control-label">类型</label>

            <div class="col-sm-10">
              <input type="text" name="type" class="form-control"  id="typeId">
            </div>
          </div>
          
          
          <div class="form-group">
            <label for="contentId" class="col-sm-2 control-label">发布内容</label>
            <div class="col-sm-10">
              <input type="text" name="content" class="form-control"  id="contentId">
            </div>
          </div>
         
        </div>
        <!-- /.box-body -->
        <div class="box-footer">
          <button type="button" class="btn btn-default btn-cancel">取消</button>
          <button type="button" class="btn btn-info pull-right btn-save">确定</button>
        </div>
        <!-- /.box-footer -->
      </form>
    </div>
<script type="text/javascript" src="bower_components/ztree/jquery.ztree.all.min.js"></script>
<script type="text/javascript" src="bower_components/layer/layer.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	 //页面加载完成以后初始化页面
	  doInitFormData();
});

	$(".box-footer")
		.on("click",".btn-cancel",doCancel)
	$(".box-footer")
	  	.on("click",".btn-save",doSaveOrUpdate)

	function doCancel(){
		$("#mainContentId").removeData("rowData");
		$("#mainContentId").load("notice/notice_list");
 	}

	function doSaveOrUpdate(){
		 var rowData=$("#mainContentId").data("rowData");
		 debugger
		 //1.获取表单数据
		 var params=doGetEditFormData();
		 //if(rowData)params.id=rowData.notice.id;
		 //2.发起异步请求
		 var insertUrl="notice/doInsertNotice";
		 var updateUrl="notice/doUpdateObject";
		 var url=rowData?updateUrl:insertUrl;
		 console.log(params);
		 $.post(url,params,function(result){
			 if(result.state==1){
				 alert(result.message);
				 doCancel();
			 }else{
				alert(result.message);
			 }
		 })
	}

	function doGetEditFormData(){
		 var data = $("#mainContentId").data("rowData");
		 debugger
		 var params={
		      "title":$("#titleId").val(),
		      "type":$("#typeId").val(),
		      "content":$("#contentId").val(),
	          "empId":$("#empId").data("empId"),
	          //"id":data.result.id
		 }
		 if(data)params.id=data.result.id;
		 var roleIds=new Array();
		 $("#rolesId input[type='checkbox']")
		 .each(function(){
			 if($(this).prop("checked")){
				 roleIds.push($(this).val())
			 }
		 });
		 params.roleIds=roleIds.toString();
		 console.log(params);
		 return params;
		 
	 }

	function doInitFormData(){
		  
		   var data=$("#mainContentId").data("rowData");
		   if(!data)return;
		   //$("#pwdDiv").remove();
			 console.log(data);
			 //初始化用户信息 
			 $("#titleId").val(data.result.title);	
			 $("#typeId").val(data.result.type);
			 $("#contentId").val(data.result.content);
		}
</script>
    
    
    
    
    
    
    